
 $(function() {
	//openDB();
	//selectNewData();
 });
function createtable(){
	
	var createsql = 'create table if not exists mxzqgy('
	          +'"personid" char(100),'
			  +'"name" char(100),'
			  +'"sex" char(100),'
			  +'"happentime" char(100),'
			  +'"visityType" char(20),'
			  +'"sfbr" char(20),'
			  +'"tgrgx" char(200),'
			  +'"zz" char(20),'
			  +'"zzqt" char(200),'
			  +'"gy" char(100),'
			  +'"dy" char(100),'
			  +'"weight" char(100),'
			  +'"heart" char(100),'
			  +'"hx" char(100),'
			  +'"tzqt" char(200),'
			  +'"sfjy" char(20),'//是否戒烟
			  +'"sfjj" char(20),'//是否戒酒
			  +'"ydcs" char(20),'//运动次数
			  +'"ydsc" char(20),'//运动时长
			  +'"ysqk" char(20),'
			  +'"xltz" char(20),'//心里调整
			  +'"zyxw" char(20),'
			  +'"fyycx" char(20),'//服药依从性
			  +'"ywblfy" char(300),'//药物不良反应
			  +'"ywmc1" char(200),'//药物名称1
			  +'"mr1" char(50),'//每日1
			  +'"mc1" char(50),'//每次1
			  +'"ywmc2" char(200),'//药物名称2
			  +'"mr2" char(50),'//每日2
			  +'"mc2" char(50),'//每次2
			  +'"ywmc3" char(200),'//药物名称3
			  +'"mr3" char(50),'//每日3
			  +'"mc3" char(50),'//每次3			  
			  +'"sffl" char(20),'//此次随访分类
			  +'"sfys" char(20)'
	          +')' 
		app.InsertSql(createsql);	 
	// executeSQL(createsql);//创建表单
}  
function saveInfo(){
	//createtable();
	var happentime = $("#happentime").val();//随访日期
	var visityType = $("input[name='sffs']:checked").val();//随访方式
	var sfbr = $("input[name='sfbr']:checked").val();//是否本人
	var tgrgx = $("#tgrgx").val();//提供信息者与被访人关系
	var zz = $("input[name='zz']:checked").val();//症状
	var zzqt = $("#zzqt").val();//症状其他
	var gy = $("#gy").val();//高压	
	var dy = $("#dy").val();//低压
	var weight = $("#weight").val();//体重
	var heart = $("#heart").val();//心率
	var hx = $("#hx").val();//呼吸
	var tzqt = $("#tzqt").val();//体征其他	
	var sfjy = $("input[name='sfjy']:checked").val();//是否戒烟
	var sfjj = $("input[name='sfjj']:checked").val();//是否戒酒
	var ydcs = $("#ydcs").val();//运动次数	
	var ydsc = $("#ydsc").val();//运动时长
	var ysqk = $("input[name='ysqk']:checked").val();//饮食情况
	var xltz = $("input[name='xltz']:checked").val();//心里调整
	var zyxw = $("input[name='zyxw']:checked").val();//遵医行为
	var fyycx = $("input[name='fyycx']:checked").val();//服药依从性
	var ywblfy = $("input[name='ywblfy']:checked").val();//药物不良反应
	var ywmc1 = $("#ywmc1").val();//药物名称1
	var mr1 = $("#mr1").val();//每日1
	var mc1 = $("#mc1").val();//每次1
	var ywmc2 = $("#ywmc2").val();//药物名称2
	var mr2 = $("#mr2").val();//每日2
	var mc2 = $("#mc2").val();//每次2
	var ywmc3 = $("#ywmc3").val();//药物名称3
	var mr3 = $("#mr3").val();//每日3
	var mc3 = $("#mc3").val();//每次3
	
	var sffl = $("input[name='sffl']:checked").val();//此次随访分类
	var sfys = $("#sfys").val();//随访医生
	var insertsql = "insert into mxzqgy(id,personid,name,sex,happentime,visityType,sfbr,tgrgx,zz,zzqt,gy,dy,weight,heart,"
	                    +"hx,tzqt,sfjy,sfjj,ydcs,ydsc,ysqk,xltz,zyxw,fyycx,ywblfy,ywmc1,mr1,mc1,ywmc2,mr2,mc2,ywmc3,mr3,mc3,sffl,sfys) values("
					+"'"+Math.floor(Math.random()*10)+"',"
					+"'"+personid+"',"
					+"'"+name+"',"
					+"'"+sex+"',"
					+"'"+happentime+"',"
					+"'"+visityType+"',"
					+"'"+sfbr+"',"
					+"'"+tgrgx+"',"
					+"'"+zz+"',"
					+"'"+zzqt+"',"
					+"'"+gy+"',"
					+"'"+dy+"',"
					+"'"+weight+"',"
					+"'"+heart+"',"
					+"'"+hx+"',"
					+"'"+tzqt+"',"
					+"'"+sfjy+"',"
					+"'"+sfjj+"',"
					+"'"+ydcs+"',"
					+"'"+ydsc+"',"
					+"'"+ysqk+"',"
					+"'"+xltz+"',"
					+"'"+zyxw+"',"
					+"'"+fyycx+"',"
					+"'"+ywblfy+"',"
					+"'"+ywmc1+"',"
					+"'"+mr1+"',"
					+"'"+mc1+"',"
					+"'"+ywmc2+"',"
					+"'"+mr2+"',"
					+"'"+mc2+"',"
					+"'"+ywmc3+"',"
					+"'"+mr3+"',"
					+"'"+mc3+"',"			  
					+"'"+sffl+"',"
					+"'"+sfys+"'"
					+")";
	app.InsertSql(insertsql);	 
	// transactionDB();//开启事务
	// executeSQL(insertsql);
	// transactionDBcommit();
	// closeDB();
	// selectSQL();
	
}

function selectNewData(){
	var selectsql = 'select * from mxzqgy where personid='+personid+" order by happentime desc";
		document.addEventListener('plusready', function(){
			plus.sqlite.selectSql({
				name: 'pad',
				sql: selectsql,
				success: function(data){
					console.log('selectSql success: ');
					// for(var i in data){
					// 	console.log(data[i].name); 
					// }
					if(null!=data&&data.length>0){
						var info = data[0];
						$("#xm").html(info.name);
						$("#xb").html(info.sex);
						$("#happentime").val(info.happentime);//随访日期
						$("input[name=sffs]:eq("+info.visityType+")").attr("checked",'checked');//随访方式
						$("input[name=sfbr]:eq("+info.sfbr+")").attr("checked",'checked');//是否本人
						$("#tgrgx").val(info.tgrgx);//提供信息者与被访人关系
						$("input[name=zz]:eq("+info.zz+")").attr("checked",'checked');//症状
						$("#zzqt").val(info.zzqt);//症状其他
						$("#gy").val(info.gy);//高压	
						$("#dy").val(info.dy);//低压
						$("#weight").val(info.weight);//体重
						$("#heart").val(info.heart);//心率
						$("#hx").val(info.hx);//呼吸
						$("#tzqt").val(info.tzqt);//体征其他	
						$("input[name=sfjy]:eq("+info.sfjy+")").attr("checked",'checked');//是否戒烟
						$("input[name=sfjj]:eq("+info.sfjj+")").attr("checked",'checked');//是否戒酒
						$("#ydcs").val(info.ydcs);//运动次数	
						$("#ydsc").val(info.ydsc);//运动时长
						$("input[name=ysqk]:eq("+info.ysqk+")").attr("checked",'checked');//饮食情况
						$("input[name=xltz]:eq("+info.xltz+")").attr("checked",'checked');//心里调整
						$("input[name=zyxw]:eq("+info.zyxw+")").attr("checked",'checked');//遵医行为
						$("input[name=fyycx]:eq("+info.fyycx+")").attr("checked",'checked');//服药依从性
						$("input[name=ywblfy]:eq("+info.ywblfy+")").attr("checked",'checked');//药物不良反应
						$("#ywmc1").val(info.ywmc1);//药物名称1
						$("#mr1").val(info.mr1);//每日1
						$("#mc1").val(info.mc1);//每次1
						$("#ywmc2").val(info.ywmc2);//药物名称2
						$("#mr2").val(info.mr2);//每日2
						$("#mc2").val(info.mc2);//每次2
						$("#ywmc3").val(info.ywmc3);//药物名称3
						$("#mr3").val(info.mr3);//每日3
						$("#mc3").val(info.mc3);//每次3
						$("input[name=sffl]:eq("+info.sffl+")").attr("checked",'checked');//此次随访分类
						$("#sfys").val(info.sfys);//随访医生
					}
					
					
				},
				fail: function(e){
					console.log('selectSql failed: '+JSON.stringify(e));
				}
			});
		});


}